package stark.app.function.novelreader;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.hjq.bar.TitleBar;
import com.stark.novelreader.ReaderEntry;
import com.stark.novelreader.book.utils.media.MediaStoreHelper;

import java.io.File;

import stark.app.R;
import stark.app.databinding.ActivityLocalNovelBinding;
import stark.common.basic.base.BaseTitleBarActivity;

/**
 * Author：daizhongbin on 2021/6/9
 * Email：1027154338@qq.com
 * Desc:
 */
public class LocalNovelActivity extends BaseTitleBarActivity<ActivityLocalNovelBinding> {

    private LocalNovelAdapter mAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_local_novel;
    }

    @Override
    protected void initView() {
        super.initView();
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mDataBinding.recyclerView.setLayoutManager(layoutManager);

        mAdapter = new LocalNovelAdapter();
        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                File file = mAdapter.getItem(position);
                ReaderEntry.readFile(LocalNovelActivity.this, file);
            }
        });
        mDataBinding.recyclerView.setAdapter(mAdapter);

    }

    @NonNull
    @Override
    protected TitleBar getTitleBar() {
        return mDataBinding.titleBar;
    }

    @Override
    protected void initData() {
        MediaStoreHelper.getAllBookFile(LocalNovelActivity.this,
                files -> mAdapter.setNewInstance(files));
    }

}
